package com.emm.yixun.mobile.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.model.ArmorTeamModel;

public class ArmoryTeamAdapter extends BaseAdapter {

	Context context;

	ArrayList<ArmorTeamModel> list;

	// 1数量 2 金额
	int type = 1;

	public ArmoryTeamAdapter(Context context, ArrayList<ArmorTeamModel> list) {
		this.context = context;
		this.list = list;
	}

	/** 1数量 2 金额 */
	public void SetType(int type) {
		Log.v("type", "type:" + type);
		this.type = type;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? null : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoudlerTeamitem v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.armory_adapter_team_item, null);
			v = new ViewHoudlerTeamitem();
			v.name1 = (TextView) convertView.findViewById(R.id.name1);
			v.name2 = (TextView) convertView.findViewById(R.id.name2);
			v.name3 = (TextView) convertView.findViewById(R.id.name3);
			v.icon_image = (ImageView) convertView.findViewById(R.id.icon_image);
			v.title_name = (TextView) convertView.findViewById(R.id.title_name);
			v.content1 = (TextView) convertView.findViewById(R.id.content1);
			v.content2 = (TextView) convertView.findViewById(R.id.content2);
			v.content3 = (TextView) convertView.findViewById(R.id.content3);
			convertView.setTag(v);
		} else {
			v = (ViewHoudlerTeamitem) convertView.getTag();
		}
		if (position == 0) {
			v.icon_image.setImageResource(R.drawable.icon_phb_rc_new);
		} else if (position == 1) {
			v.icon_image.setImageResource(R.drawable.icon_phb_rg_new);
		} else {
			v.icon_image.setImageResource(R.drawable.icon_phb_qy_new);
		}

		if (list.get(position).getMessag().size() == 1) {//认筹
			v.name1.setText(list.get(position).getMessag().get(0).getName());
			v.name2.setText("???");
			v.name3.setText("???");
			v.title_name.setText(list.get(position).getTitle());
			if (type == 1) {
				v.content1.setText("（" + list.get(position).getMessag().get(0).getNumber() + "）");
				v.content2.setText("（0）");
				v.content3.setText("（0）");
			} else {
				v.content1.setText("（" + list.get(position).getMessag().get(0).getPrice() + "万元）");
				v.content2.setText("（0万元）");
				v.content3.setText("（0万元）");
			}
		} else if (list.get(position).getMessag().size() == 2) {//认购

			v.name1.setText(list.get(position).getMessag().get(0).getName());
			v.name2.setText(list.get(position).getMessag().get(1).getName());
			v.name3.setText("???");
			v.title_name.setText(list.get(position).getTitle());
			if (type == 1) {
				v.content1.setText("（" + list.get(position).getMessag().get(0).getNumber() + "）");
				v.content2.setText("（" + list.get(position).getMessag().get(1).getNumber() + "）");
				v.content3.setText("（0）");
			} else {
				v.content1.setText("（" + list.get(position).getMessag().get(0).getPrice() + "万元）");
				v.content2.setText("（" + list.get(position).getMessag().get(1).getPrice() + "万元）");
				v.content3.setText("（0万元）");
			}
		} else {//签约
			v.name1.setText(list.get(position).getMessag().get(0).getName());
			v.name2.setText(list.get(position).getMessag().get(1).getName());
			v.name3.setText(list.get(position).getMessag().get(2).getName());
			v.title_name.setText(list.get(position).getTitle());
			if (type == 1) {
				v.content1.setText("（" + list.get(position).getMessag().get(0).getNumber() + "）");
				v.content2.setText("（" + list.get(position).getMessag().get(1).getNumber() + "）");
				v.content3.setText("（" + list.get(position).getMessag().get(2).getNumber() + "）");
			} else {
				v.content1.setText("（" + list.get(position).getMessag().get(0).getPrice() + "万元）");
				v.content2.setText("（" + list.get(position).getMessag().get(1).getPrice() + "万元）");
				v.content3.setText("（" + list.get(position).getMessag().get(2).getPrice() + "万元）");
			}
		}
		return convertView;
	}

	public static class ViewHoudlerTeamitem {
		TextView title_name, name1, name2, name3, content1, content2, content3;
		ImageView icon_image;

	}

}